package com.ttg.common.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author ZQ
 * @version 1.0
 * @Description
 * @date 2020/12/17 14:30
 */
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
    private String forMate = "yyyy-MM-dd HH:mm:ss";
    public LocalDateTimeDeserializer(){
    }
    public LocalDateTimeDeserializer(String f){
        this.forMate = f;
    }
    @Override
    public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        return LocalDateTime.parse(parser.getValueAsString(), DateTimeFormatter.ofPattern(forMate));
    }
}
